package com.ts.api.module.match.core;

import com.gitee.apanlh.spring.BeanContextUtils;

import java.util.EnumMap;
import java.util.Map;

/**
 *  抽象基类-注册上下文
 *
 *  @author Pan
 */
public abstract class MatchRegisterContext<K extends Enum<K>, V> {

    private Map<K, V> registerMap;

    /**
     *  私有函数
     */
    private MatchRegisterContext() {
        super();
    }

    /**
     *  初始化构造函数
     *
     *  @param keyType
     */
    public MatchRegisterContext(Class<K> keyType) {
        this.registerMap = new EnumMap<>(keyType);
    }

    /**
     *  初始化注册
     *
     *  @param e
     *  @param strategyClass
     */
    public <S extends V> void register(K e, Class<S> strategyClass) {
        registerMap.put(e, BeanContextUtils.getBean(strategyClass));
    }

    /**
     *  获取上下文
     *
     *  @param e
     *  @return
     */
    public V getContext(K e) {
        return registerMap.get(e);
    }
}
